package com.patterns.java.interpret;

/**
 * 解释器测试入口
 * @author 三多
 * @Time 2021/10/13
 */
public class InterpretDemo {
    public static void main(String[] args) {
        //获取男性表达式
        Expression isMale = getMaleExpression();
        //获取已婚女性表达式
        Expression isMarriedWoman = getMarriedWomanExpression();

        System.out.println("Robert is Male? "+ isMale.interpret("Robert"));
        System.out.println("Julie is a Married Woman? "+ isMarriedWoman.interpret("Julie Married"));

    }

    /**
     * 规则：Robert 和 Robert 都是男性
     * @return getMaleExpression
     */
    private static Expression getMaleExpression() {
        TerminalExpression robert = new TerminalExpression("Robert");
        TerminalExpression john = new TerminalExpression("John");
        return new OrExpression(robert,john);
    }

    /**
     * 规则：Julie 是已婚女性
     * @return
     */
    private static Expression getMarriedWomanExpression() {
        TerminalExpression julie = new TerminalExpression("Julie");
        TerminalExpression married = new TerminalExpression("Married");
        return new AndExpression(julie,married);
    }
}
